#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
int main(){
	int n,l,k,sumLen = 0;
	int a[10240],len[10240];
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> len[i];
		sumLen += len[i];
	}
	int temp,max = 1;
	for(int i = 0;i < k;i++){
		cin >> temp;
		if(temp<sumLen){
			int j = 0;
			while(temp>=len[j]){
				temp -= len[j];
				j++;
			}
			if(j+1>max) max = j+1;
			cout << a[j]+temp*4 << endl;
		}else{
			cout << "Illegal Access" << endl;
		}
		cout << max;
	}
	
	return 0;
}
